home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 342_01.zip / I8255F05.C < prev    next >
C/C++ Source or Header  |  1993-04-03  |  2KB  |  78 lines

  1. /*-
  2.  *  ----------------------------------------------------------------------
  3.  *  File        :   I8255F05.C
  4.  *  Creator     :   Blake Miller
  5.  *  Version     :   01.00.00        February 1991
  6.  *  Language    :   Microsoft C     Version 5.1
  7.  *  Purpose     :   Intel 8255 Compatible Digital IO Functions
  8.  *              :   8255 Byte Put Function
  9.  *  ----------------------------------------------------------------------
  10.  */
  11.  
  12. #define  I8255F05_C_DEFINED  1
  13. #include "I8255FN.H"
  14. #undef   I8255F05_C_DEFINED
  15.  
  16. void I8255_put_byte (I8255DAT *data, int p_num, unsigned char p_dat);
  17.  
  18. /*- I8255 : Byte Put -------------------------**
  19.  *  Write one of the bytes in the 8255.
  20.  *  The port number should be 1 - 3 as follows:
  21.  *  1 = Port A,  2 = Port B,  3 = Port C
  22.  *  Passed:
  23.  *      pointer         :   I8255DAT
  24.  *      integer         :   port number
  25.  *      unsigned char   :   port data
  26.  *  Returns:
  27.  *      nothing
  28.  *      Loads stat with any error ID.
  29.  */
  30. void I8255_put_byte (I8255DAT *data, int p_num, unsigned char p_dat)
  31.     {
  32.     int             padd;   /* port address */
  33.  
  34.     /*  Make sure the port requested is valid.
  35.      *  Three ports.
  36.      */
  37.     if ( (p_num < 1) || (p_num > 3) ){
  38.         data->stat = I8255_ST_BP;
  39.         return;
  40.         }
  41.  
  42.     /*  Decrement the port so we have zero offset.
  43.      *  port number = ( 0 - 2 )
  44.      */
  45.     p_num--;
  46.  
  47.     /*  Prepare to output data:
  48.      *  Obtain port address.
  49.      *  Save the port data.
  50.      */
  51.     switch ( p_num ){
  52.         case 0:         /* port A   */
  53.             padd = I8255_PORTA(data->base);
  54.             data->adat = p_dat;
  55.             break;
  56.         case 1:         /* port B   */
  57.             padd = I8255_PORTB(data->base);
  58.             data->bdat = p_dat;
  59.             break;
  60.         case 2:         /* port C   */
  61.             padd = I8255_PORTC(data->base);
  62.             data->cdat = p_dat;
  63.             break;
  64.         default:        /* bad port number  */
  65.             return;
  66.             break;
  67.         }
  68.  
  69.     chp_portwt ( padd, p_dat );
  70.     data->stat = I8255_ST_OK;
  71.     }
  72.  
  73. /*-
  74.  *  ----------------------------------------------------------------------
  75.  *  END I8255F05.C Source File
  76.  *  ----------------------------------------------------------------------
  77.  */
  78.